import 'package:flutter/material.dart';
import 'package:fluro/fluro.dart';
import 'package:tudouapp/widgets/account/page_msg.dart';

import '../widgets/main/app_main.dart';

import '../widgets/order/page_product_detail.dart';
import '../widgets/order/screen_product_list.dart';
import '../widgets/order/screen_product_list_cate.dart';
import '../widgets/order/screen_history_detail.dart';
import '../widgets/order/screen_cart.dart';
import '../widgets/order/screen_sales_list.dart';

import '../widgets/order/screen_home.dart';
import '../widgets/order/screen_checkout.dart';
import '../widgets/order/page_outofstock.dart';
import '../widgets/order/page_time.dart';
import '../widgets/order/page_payment_channel.dart';
import '../widgets/order/page_history_payment_channel.dart';
import '../widgets/order/page_comment.dart';
import '../widgets/login/page_signin.dart';
import '../widgets/account/page_address.dart';
import '../widgets/account/screen_address_list.dart';
import '../widgets/account/page_redeem.dart';
import '../widgets/account/page_switch.dart';
import '../widgets/account/screen_voucher_list.dart';
import '../widgets/account/screen_msg_main.dart';
import '../widgets/account/page_wholesale_apply.dart';
import '../widgets/account/page_voucher_usage.dart';

import '../widgets/account/screen_voucher_list.dart';
import '../widgets/menu/screen_home.dart';
import '../util/webview.dart';

class AppRoutes {
  static String root = "/";
  static String appMain = "/app_main";
  static String productDetail = "/product_detail";
  static String productList = "/product_list";
  static String productListCate = "/product_list_cate";
  static String voucherList = "/voucher_list";
  static String subCategoryList = "/sub_category";
  static String salesList = "/sales_list";
  static String outofStock = "/out_of_stock";

  static String historyDetail = "/history_detail";
  static String orderCart = "/order_cart";
  static String orderHome = "/order_home";
  static String orderTime = "/order_time";
  static String orderComment = "/order_comment";
  static String orderPaymentChannel = "/order_payment_channel";
  static String historyPaymentChannel = "/history_payment_channel";
  static String orderCheckout = "/order_checkout";
  static String accountAddr = "/account_addr";
  static String accountAddrList = "/account_addr_list";
  static String accountRedeem = "/account_redeem";
  static String accountMsg = "/account_msg";
  static String accountMsgMain = "/account_msg_main";
  static String accountSwitch = "/account_switch";
  static String accountWholesaleApply = "/account_wholesale_apply";
  static String accountVoucherUsage = "/account_voucher_usage";
  static String loginSignin = "/login_signin";

  static String webview = "/webview/:url";


  static void configureRoutes(FluroRouter router) {
    router.notFoundHandler = new Handler(
        handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
          print("ROUTE WAS NOT FOUND !!!");
        }
    );

    router.define(webview, handler: webviewRouteHandler);

    router.define(appMain, handler: appMainRouteHandler);
    router.define(salesList, handler: salesListRouteHandler);
    router.define(outofStock, handler: outofStockRouteHandler);

    router.define(productList, handler: productListRouteHandler);
    router.define(subCategoryList, handler: subCategoryListRouteHandler);
    router.define(productListCate, handler: productListCateRouteHandler);
    router.define(voucherList, handler: voucherListRouteHandler);
    router.define(productDetail, handler: productDetailRouteHandler);
    router.define(historyDetail, handler: historyDetailRouteHandler);
    router.define(orderCheckout, handler: orderCheckoutRouteHandler);
    router.define(orderCart, handler: orderCartRouteHandler);
    router.define(orderHome, handler: orderHomeRouteHandler);
    router.define(orderTime, handler: orderTimeRouteHandler);
    router.define(orderComment, handler: orderCommentRouteHandler);
    router.define(orderPaymentChannel, handler: orderPaymentChannelRouteHandler);
    router.define(historyPaymentChannel, handler: historyPaymentChannelRouteHandler);
    router.define(loginSignin, handler: loginSigninRouteHandler);
    router.define(accountAddr, handler: accountAddrRouteHandler);
    router.define(accountAddrList, handler: accountAddrListRouteHandler);
    router.define(accountRedeem, handler: accountRedeemRouteHandler);
    router.define(accountMsg, handler: accountMsgRouteHandler);
    router.define(accountSwitch, handler: accountSwitchRouteHandler);
    router.define(accountWholesaleApply, handler: accountWholesaleApplyRouteHandler);
    router.define(accountVoucherUsage, handler: accountVoucherUsageRouteHandler);
    router.define(accountMsgMain, handler: accountMsgMainRouteHandler);
    // router.define(profileMyinfo, handler: profileMyinfoRouteHandler);
    // router.define(profileMemberCheckout, handler: profileMemberCheckoutRouteHandler);
    // router.define(profileMemberEnroll, handler: profileMemberEnrollRouteHandler);
  }
}

Handler appMainRouteHandler =new Handler(
    handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
      return new AppMainView();
    }
);

var productDetailRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  int prod_id = int.parse(params["prod_id"]!.first);
  return new ProductDetailPage(
    prod_id,
  );
});

var historyDetailRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  String detail = params["detail"]?.first ?? '';
  return new HistoryDetailScreen(
    detail,
  );
});

var productListRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  String param = params["param"]!.first;
  return new ProductListScreen(param);
});

var productListCateRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  String param = params["param"]!.first;
  return new ProductListCateScreen(param);
});

var outofStockRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  return new OutofStockPage();
});
var salesListRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  return new SalesListScreen();
});
var orderHomeRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  return new OrderHomeScreen();
});
var subCategoryListRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  return new ShopPage();
});
var orderCartRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  return new OrderCartScreen();
});

var orderTimeRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  return new OrderTimePage();
});

var orderPaymentChannelRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  return new OrderPaymentChannelPage();
});

var historyPaymentChannelRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  String channels = params["channels"]!.first;
  return new HistoryPaymentChannelPage(channels);
});

var orderCommentRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  return new OrderCommentPage();
});

var orderCheckoutRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  return new OrderCheckoutScreen();
});

var loginSigninRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  return new LoginSigninPage();
});

var accountAddrRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  return new AccountAddressPage();
});

var accountAddrListRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  return new AccountAddressListScreen();
});

var accountRedeemRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  // String type = params["type"]?.first ?? '';
  return new AccountRedeemPage();
});

// var accountMsgRouteHandler =
//     new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
//   return new AccountMsgMainScreen();
// });

var accountSwitchRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  return new AccountSwitchPage();
});

var accountWholesaleApplyRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  return new AccountWholesaleApplyPage();
});

var accountMsgMainRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  return new AccountMsgMainScreen();
  ;
});

var accountMsgRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  // String date = params["date"]?.first ?? '';
  // String subject = params["subject"]?.first ?? '';
  // String content = params["content"]?.first ?? '';
  return new AccountMsgPage();
  // return new AccountMsgPage(iv_date: date, iv_subject: subject, iv_content: content);
});

var voucherListRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  String scenario = params["scenario"]?.first ?? '';
  return new AccountVouchersListScreen(scenario);
});

var accountVoucherUsageRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  String id = params["id"]?.first ?? '';
  return new AccountVoucherUsagePage(id);
});

var webviewRouteHandler =
    new Handler(handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
  return new WebView(url: params['url']![0]);
});
